<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="org.apache.commons.lang.StringUtils" %>
<%@ taglib prefix="c"
           uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
</head>
<body>
    <div align="center">

    <div style="margin-top: 150px;">
        <%

            String code = request.getParameter("code"); //临时授权code

            if (StringUtils.isEmpty(code)) {
                String client_id = "7A4796A291CE43B1"; //创建应用后，分配应用的appSecret
                String appKey = "yb1OQpps"; //创建应用后，分配给应用的appKey
                String response_type = "code"; //授权类型，此值固定为“code”
                String redirect_uri = "http://172.30.5.96:8080/"; //回调地址，如果为空，系统默认填写创建应用时的地址，否则为当前填写的redirect_uri
                String authorize_url = "https://opentest.jss.com.cn/authorize"; //授权url
                StringBuilder sb = new StringBuilder();
                sb.append(authorize_url.toString()).append("?")
                        .append("client_id").append("=").append(client_id).append("&")
                        .append("appKey").append("=").append(appKey).append("&")
                        .append("response_type").append("=").append(response_type).append("&")
                        .append("redirect_uri").append("=").append(redirect_uri);
                out.write("<a href=\"" + sb.toString() + "\"><button style='cursor:pointer;color:red;width=50px;height:50px;'>获取授权</button></a>");
            } else {
                StringBuilder _url = new StringBuilder("http://172.30.5.96:8080/token?");
                _url.append(request.getQueryString());
                out.write("<a href=" + _url.toString() + "><button style='cursor:pointer;color:red;width=50px;height:50px;'>授权成功，获取认证</button></a>");
            }
        %>
    </div>

    </div>
</body>
</html>
